package com.banyuan.filter;


import javax.servlet.*;
import java.io.IOException;

public class CharsetEncodingFilter implements Filter {
    private String encoding;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
            servletRequest.setCharacterEncoding(encoding);
            servletResponse.setCharacterEncoding(encoding);
            filterChain.doFilter(servletRequest, servletResponse);
            //  放行
    }

    @Override
    public void destroy() {

    }
}
